<?php
//joker
declare(strict_types=1);

namespace app\store\controller;

use app\store\service\SystemConfig as ServiceSystemConfig;
use app\store\validate\SystemConfig as ValidateSystemConfig;
use think\facade\Request;

/**
 * 配置管理
 * Class User
 * @package app\store\controller
 */
class SystemConfig extends Controller
{
    /**
     * 获取配置信息
     * @return json
     * @throws \think\db\exception\DbException
     */
    public function get()
    {
        if (!Request::isPost())
            return $this->renderError('请求方式错误');
        //接收参数post
        $param = array(
            'key' => Request::post('key/a', []), //key数组
        );
        $validate = new ValidateSystemConfig();
        if (!$validate->scene('get')->check($param))
            return $this->renderError($validate->getError());
        $data = ServiceSystemConfig::get($param['key']);
        return $this->renderSuccess($data);
    }

    /**
     * 批量设置配置信息
     * @return json
     */
    public function batchSet()
    {
        if (!Request::isPost())
            return $this->renderError('请求方式错误');
        //接收参数post
        $param = array(
            'data' => Request::post('data/a',[])
        );
        $validate = new ValidateSystemConfig();
        if (!$validate->scene('batchSet')->check($param))
            return $this->renderError($validate->getError());
        ServiceSystemConfig::batchSet($param['data']);
        return $this->renderSuccess();
    }
}
